package Homework1Shapes;

import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

public class ShapeCollection 
{
	private List<Shape> shapes;
	
	//Constructor
	ShapeCollection()
	{
		shapes = new ArrayList<Shape>();
	}
	
	//add a shape to the list
	public void addShape(Shape shape)
	{
		shapes.add(shape);
	}
	
	//get the number of shapes in the list
	public int getNumberOfShapes()
	{
		return shapes.size();
	}
	
	//sort the shapes in the collection
	public void sortShapes()
	{
		boolean done = false;
		
		while (!done)
		{
			done = true;
			
			for (int i = 0; i < shapes.size() - 1; i++)
			{
				Shape one = shapes.get(i);
				Shape two = shapes.get(i+1);
				
				if (one.numSides > two.numSides)
				{
					Collections.swap(shapes, i, i+1);
					done = false;
				}
			}
		}
	}
	
	//display the shapes in the collection
	public void displayShapes()
	{
		for(Shape s : shapes)
		{
			s.display();
		}
	}
}
